package com.ea.eadp.nexus.test.pageDefinition;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import com.ea.eadp.nexus.test.common.Constant;
import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.WebElement;
import org.testng.Assert;

public class SigninPageWeb2 extends Signin_Web {
    protected static final String bruteForceErrorMessage = "Too many attempts, retry in a few minutes";

    public SigninPageWeb2(WebDriver driver) {
        super(driver);
        this.setUri(getWeb2ConnectUrl());
    }
    
    private static String getWeb2ConnectUrl() {
        String format = "%s/connect/auth?client_id=%s&response_type=code&display=web2/login&redirect_uri=%s";
        return String.format(
                format,
                TestUtil.BaseConnectURI(),
                "new-web2-test-client",
                Constant.EA_URL
        );
    }
    public void verifyBruteForceErrorMessgeExist() {
        WebElement element = driver.findElement(By.cssSelector("#resend-error-code"));
        Assert.assertNotNull(element, "not able to locate the brute force error message");
        Assert.assertTrue(element.getText().contains(bruteForceErrorMessage));
    }
    public void verifyBruteForceErrorMessgeExist(boolean exist) {
        if (exist){
            verifyBruteForceErrorMessgeExist();
            return;
        }
        WebElement element = driver.findElement(By.cssSelector("#resend-error-code"));
        Assert.assertNotNull(element, "not able to locate the brute force error message");
        Assert.assertFalse(element.getText().contains(bruteForceErrorMessage));
    }

    public void clicktoCreateAccount() {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//*[@id=\"panel-registration-box\"]/div[2]/div/p/a")).click();
    }
}
